//
//  CYMineSimpleInfoCell.m
//  cyjf
//
//  Created by tauCross on 2017/5/11.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYMineSimpleInfoCell.h"



@implementation CYMineSimpleInfoCellObject

@end



@interface CYMineSimpleInfoCell ()

@property(nonatomic, strong)UILabel *totalBalanceDescLabel;
@property(nonatomic, strong)UILabel *totalBalanceLabel;
@property(nonatomic, strong)UILabel *availableBalanceDescLabel;
@property(nonatomic, strong)UILabel *availableBalanceLabel;
@property(nonatomic, strong)UILabel *incomeDescLabel;
@property(nonatomic, strong)UILabel *incomeLabel;
@property(nonatomic, strong)UIImageView *arrowImageView;
@property(nonatomic, strong)UIImageView *line;
@property(nonatomic, strong)CYMineSimpleInfoCellObject *object;

@end


@implementation CYMineSimpleInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.totalBalanceDescLabel = [self descLabelWithText:@"总资产(元)"];
        [self.contentView addSubview:self.totalBalanceDescLabel];
        
        self.availableBalanceDescLabel = [self descLabelWithText:@"可用余额(元)"];
        [self.contentView addSubview:self.availableBalanceDescLabel];
        
        self.incomeDescLabel = [self descLabelWithText:@"累计收益(元)"];
        [self.contentView addSubview:self.incomeDescLabel];
        
        self.totalBalanceLabel = [[UILabel alloc] init];
        self.totalBalanceLabel.textColor = HEXCOLOR(@"444444");
        self.totalBalanceLabel.font = [UIFont systemFontOfSize:38];
        [self.contentView addSubview:self.totalBalanceLabel];
        
        self.availableBalanceLabel = [[UILabel alloc] init];
        self.availableBalanceLabel.textColor = HEXCOLOR(@"444444");
        self.availableBalanceLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:self.availableBalanceLabel];
        
        self.incomeLabel = [[UILabel alloc] init];
        self.incomeLabel.textColor = HEXCOLOR(@"444444");
        self.incomeLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:self.incomeLabel];
        
        self.arrowImageView = [[UIImageView alloc] initWithImage:CYImage(@"public_cell_arrow")];
        [self.contentView addSubview:self.arrowImageView];
        
        self.line = [UIImageView cy_imageLineWithColor:HEXCOLOR(@"ECECEC")];
        [self.contentView addSubview:self.line];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 190;
}

- (BOOL)shouldUpdateCellWithObject:(CYMineSimpleInfoCellObject *)object
{
    self.object = object;
    
    self.totalBalanceLabel.text = object.totalBalance;
    
    self.availableBalanceLabel.text = object.availableBalance;
    
    self.incomeLabel.text = object.income;
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.totalBalanceDescLabel.left = 20;
    self.totalBalanceDescLabel.centerY = 46;
    
    [self.totalBalanceLabel sizeToFit];
    self.totalBalanceLabel.left = 20;
    self.totalBalanceLabel.centerY = 76;
    
    self.availableBalanceDescLabel.left = 20;
    self.availableBalanceDescLabel.centerY = 141;
    
    [self.availableBalanceLabel sizeToFit];
    self.availableBalanceLabel.left = 20;
    self.availableBalanceLabel.centerY = 161;
    
    self.incomeDescLabel.left = self.contentView.width / 2 + 20;
    self.incomeDescLabel.centerY = self.availableBalanceDescLabel.centerY;
    
    [self.incomeLabel sizeToFit];
    self.incomeLabel.left = self.incomeDescLabel.left;
    self.incomeLabel.centerY = self.availableBalanceLabel.centerY;
    
    self.arrowImageView.centerY = 70;
    self.arrowImageView.right = self.contentView.width - 12;
    
    self.line.width = self.contentView.width;
    self.line.height = 1 / SCREEN_SCALE;
    self.line.left = 0;
    self.line.bottom = self.contentView.height;
}

#pragma mark - Private Method
- (UILabel *)descLabelWithText:(NSString *)text
{
    UILabel *label = [[UILabel alloc] init];
    label.textColor = HEXCOLOR(@"999999");
    label.font = [UIFont systemFontOfSize:12];
    label.text = text;
    [label sizeToFit];
    return label;
}

@end
